package oop.ex2.filters;

import java.util.ArrayList;
import oop.ex2.parser.*;
import oop.ex2.filters.exceptions.FilterDataException;

/**
 * Filters file by text content.
 */
class FileTextFilter extends Filter {
    //***********************************************************************
    //  Methods :                                                           *
    //***********************************************************************
   /**
    * Returns a list with all the text nodes.
    * @return A list with all the text nodes.
    */
	public ArrayList<Filter> getTextList(){
        ArrayList<Filter> list = new ArrayList<Filter>();
        if ( _file.isFile() ){
            list.add(this);
        }
        return list;
    }   
    /**
     * Returns Filter's data.
     * @return Filter's data.
     */
    public String getData() {
        return _data;
    }
    /**
	 * Calculates the value of filter's condition.
	 *Empty implementation, to maintain
	*efficiency the condition is calculated by search engine.
	*/
    public void calculate(){}
    /**
	 *  Clones the object - return a new object with same properties.
	 */
    public Filter clone() {
        return new FileTextFilter();
    }
    /**
	 * Sets the data of the filter.
	 * @param data The data to be set.
	 * @throws FilterDataException In case of wrong filter parameters. 
	 */
    public void setData( String data ) throws FilterDataException{
        if ( data.contains(Parser.QUOTES+"") ) {
            _data = data.substring(1,data.length()-1);
        } 
        else if ( data.contains(" ") ) {
            throw new FilterDataException("Error:Invalid filter parameters");
        }
        else {
            _data = data;
        }
    }
}
